﻿using ExDUIR.NET.Declaration;
using ExDUIR.NET.Engine;
using ExDUIR.NET.Skin;
using ExDUIR.NET.Handle;
using ExDUIR.NET.Utility;
using ExDUIR.NET.Color;
using static ExDUIR.NET.Const.ExConst;
using ExDUIR.NET.Common;
using ExDUIR.NET.Control;

public class Test
{
    public class MainWindow
    {
        ExWndProcDelegate wndProc;
        ExSkin skin;
        ExButton button;
        ExLineChart linechart;
        ExObjProcDelegate objProc;

        public MainWindow()
        {
            var theme = System.IO.File.ReadAllBytes("Default.bin");//打包的主题包
            ExEngine.Init(new EngineCreationOptions
            {
                ThemeData = theme,
                CursorHandle = new ExCursorHandle(IntPtr.Zero),
                GlobalFlags = ENGINE_FLAG_DPI_ENABLE | ENGINE_FLAG_MENU_ALL
            });
            wndProc = new ExWndProcDelegate(MainWndProc);

            skin = ExSkin.CreateBuilder()
                .WithWindowName("ExDUIR")
                .WithSize(800, 600)
                .WithStyles(duiStyle: WINDOW_STYLE_MAINWINDOW | WINDOW_STYLE_BUTTON_CLOSE | WINDOW_STYLE_BUTTON_MIN | WINDOW_STYLE_MOVEABLE | WINDOW_STYLE_CENTERWINDOW |
                WINDOW_STYLE_ESCEXIT | WINDOW_STYLE_TITLE | WINDOW_STYLE_SIZEABLE | WINDOW_STYLE_HASICON)
                .WithWndProc(wndProc)
                .Build();

            button = ExButton.CreateBuilder()
                .WithParent(skin)
                .WithSize(100, 30)
                .WithLocation(100, 450)
                .WithText("测试")
                .Build();
            objProc = new ExObjProcDelegate(OnObjProc);
            linechart = ExLineChart.CreateBuilder()
                .WithParent(skin)
                .WithSize(600, 300)
                .WithLocation(50, 50)
                .WithObjProc(objProc)
                .Build();
            linechart.Timer = 500;
            skin.BackgroundColor = new ExARGB(150, 150, 150, 255);
            skin.Visible = true;

            ExEngine.Run();
            ExEngine.Uninit();
        }

       IntPtr OnObjProc(IntPtr hWnd, int hObj, int uMsg, IntPtr wParam, IntPtr lParam, IntPtr pResult)
        {
            if(uMsg == WM_TIMER)
            {
                var y = new Random().Next(30) + 30;
                linechart.Value = y;
                linechart.Invalidate();
            }
            return IntPtr.Zero;
        }

        IntPtr MainWndProc(IntPtr hWnd, int hExDui, int uMsg, IntPtr wParam, IntPtr lParam, IntPtr pResult)
        {
            if (uMsg == WM_CREATE)
            {
            }
            return IntPtr.Zero;
        }
    }

    public static void Main()
    {
        MainWindow window = new MainWindow();
    }
}